<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;

/**
 * App\ComboActivity
 *
 * @property int $id
 * @property int|null $sort
 * @property string|null $title 活动名称
 * @property string|null $thumb 封面
 * @property int|null $type 活动方式1折扣2减免价格
 * @property float|null $reduce 减免价格
 * @property float|null $rebate 折扣
 * @property int|null $rate_type 1按套餐2自定义
 * @property float|null $rate 返利
 * @property float|null $top_rate
 * @property string|null $desc 描述
 * @property string|null $content 详情
 * @property string|null $start_time 开始时间
 * @property string|null $end_time 结束时间
 * @property int|null $status 是否启用1是2否
 * @property \Carbon\Carbon|null $created_at
 * @property \Carbon\Carbon|null $updated_at
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Http\Controllers\Admin\Business\Repository\Combo[] $combo
 * @method static \Illuminate\Database\Eloquent\Builder|\App\ComboActivity whereContent($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\ComboActivity whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\ComboActivity whereDesc($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\ComboActivity whereEndTime($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\ComboActivity whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\ComboActivity whereRate($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\ComboActivity whereRateType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\ComboActivity whereRebate($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\ComboActivity whereReduce($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\ComboActivity whereSort($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\ComboActivity whereStartTime($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\ComboActivity whereStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\ComboActivity whereThumb($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\ComboActivity whereTitle($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\ComboActivity whereTopRate($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\ComboActivity whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\ComboActivity whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class ComboActivity extends Model
{
    protected $table='combo_activities';
    public function getThumbAttribute($value)
    {
        return env('APP_URL').'/storage/'.$value;
    }
    public function getStartTimeAttribute($value)
    {
       $date= Carbon::parse($value);
       return $date->year.'/'.$date->month.'/'.$date->day;
    }

    public function getEndTimeAttribute($value)
    {
        $date= Carbon::parse($value);
        return $date->month.'/'.$date->day;
    }
    public function getCreatedAtAttribute($value)
    {
        $date= Carbon::parse($value);
        return $date->year.'/'.$date->month.'/'.$date->day;

    }
    public function getUpdatedAtAttribute($value)
    {
        return  $value>$this->attributes['start_time']&&$value<$this->attributes['end_time'];

    }
    public function combo(){
        return $this->belongsToMany('App\Http\Controllers\Admin\Business\Repository\Combo','combo_activities_relation','activity_id','combo_id');
    }
}
